package com.hnair.bot.service.impl;

import com.hnair.bot.common.utils.FastDFSClient;
import com.hnair.bot.service.IPictureService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class PictureServiceImpl implements IPictureService {

	private final Logger logger = LoggerFactory.getLogger(PictureServiceImpl.class);
	
	@Override
	public String uploadPic(MultipartFile picFile) {

		String imageUrl  = null;
		
        //上传到图片服务器
        try {
            //获取图片扩展名
            String originalFilename = picFile.getOriginalFilename();
            //取扩展名，不要"."
            String extName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
            FastDFSClient client = new FastDFSClient("properties/fdfs_client.conf");
            imageUrl = client.uploadFile(picFile.getBytes(), extName);
            imageUrl = "/" + imageUrl;
            logger.info("图片上传地址：" + imageUrl);
        } catch (Exception e) {
        	logger.error("上传图片异常：", e);
        }
        return imageUrl;
	}

}
